﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using DAL.Enums;
using Commons;


namespace CacheStorage
{
    public partial class CS
    {

        private static object lockHelper1 = new object();
        private static object lockHelper2 = new object();
        private static object lockHelper3 = new object();
        private static object lockHelper4 = new object();

        public class Ad_Promotion_Company
        {
            public string CompName { get; set; }
            public int CompID { get; set; }
            public int CompDiscCount { get; set; }
            public int CompFaceCount { get; set; }
        }
        public JsonResult Get_Ad_Promotion_Company
        {
            get
            {
                const string key = "Ad_Promotion_Company";
                var result = new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                result.Data = CacheHelper.GetCache(key);
                if (result.Data == null)
                {
                    lock (lockHelper)
                    {
                        result.Data = CacheHelper.GetCache(key);
                        if (result.Data == null)
                        {
                            var instance = new List<Ad_Promotion_Company>
                                           {
                                               new Ad_Promotion_Company()
                                                   {
                                                       CompName = "广州府黑有限责任公司",
                                                    CompID = 1,
                                                    CompDiscCount = 13,
                                                    CompFaceCount = 1234,
                                                   },
                                               new Ad_Promotion_Company()
                                                   {
                                                       CompName = "广州府黑asdf责任公司",
                                                    CompID = 1,
                                                    CompDiscCount = 113,
                                                    CompFaceCount = 1234,
                                                   },
                                           };
                            CacheHelper.SetCache(key, instance, new TimeSpan(hours: 0, minutes: 30, seconds: 0));
                            result.Data = instance;
                        }
                    }
                }
                return result;
            }
        }
    }
}
